﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Queries;
using NHibernate.Expression;

namespace Almoxarifado.Models
{
    [ActiveRecord("[Usuario]")]
    public class Usuario : ActiveRecordBase<Usuario>
    {
        private int _id;
        private string _username;
        private string _password;

        [Property]
        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        [Property]
        public string Username
        {
            get { return _username; }
            set { _username = value; }
        }

        [PrimaryKey]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public static Usuario authenticate(string username, string password) 
        {
            return (Usuario)FindOne(typeof(Usuario),Expression.Eq("Username",username) & Expression.Eq("Password", password));
        }
    }
}
